import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JOptionPane;

public class GenSummaryButton extends JButton implements ActionListener {
	private GuiClient gui;

	public GenSummaryButton(GuiClient g) {
		super();
		this.gui = g;
		setText("Generate summary");

		addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		String input = JOptionPane
				.showInputDialog("Enter conversion factor, conversion unit and output unit");

		double conv = 1;
		String convUnit = "";
		String outputUnit = "";

		if (input.equals("none")) {
			convUnit = "none";
		} else {

			String[] split = input.split(" ");

			conv = Double.parseDouble(split[0]);
			convUnit = split[1];
			outputUnit = split[2];
		}

		gui.generateSummary(conv, convUnit, outputUnit);
	}
}
